<?
include("common/header.html");
include("common/left.html");
$id=$_REQUEST["id"];
if($_SESSION['memberID']==$id){
	exit("<script>alert('不可修改自己的权限');history.go(-1);</script>");
}

$sel="select parent_id from pft_member_relationship where son_id_type=2 and ship_type=1 and son_id=".$id;
$GLOBALS['le']->query($sel);
$GLOBALS['le']->fetch_assoc();
if($GLOBALS['le']->f("parent_id")!=$_SESSION['sid']){exit("<script>alert('无权修改!')</script>");}
$sel="select dname,mobile,member_auth,address from pft_member where id=".$id;
$GLOBALS['le']->query($sel);
$row = $GLOBALS['le']->fetch_assoc();
//print_r($row);
//print_r($_SESSION);//dtyep=7
$dname=$GLOBALS['le']->f("dname");
$mobile=$GLOBALS['le']->f("mobile");
$bizz=$GLOBALS['le']->f("address");
$chid=explode(",",$GLOBALS['le']->f("member_auth"));//pro,order,orderAlter,low,file,ps,notice   sale,ps,file,notice
include_once("common/auth_config.php");
//echo $_SESSION['sid'];
//exit;
//获取从属关系的供应商
include 'getDistors.php';
//$sql="select dname,cname,account,mobile,m.id,ship_type,son_id_type from pft_member_relationship r left join pft_member m on m.id=son_id where m.status in (0,3) and r.status=0 and parent_id='{$_SESSION['sid']}' and son_id_type in (3) and ship_type=1";
//$sql="select m.id from pft_member_relationship r left join pft_member m on m.id=son_id where m.status in (0,3) and r.status=0 and parent_id='{$_SESSION['sid']}' and son_id_type in (3) and ship_type=1";
$sql="select m.id,m.dname from pft_member m left join pft_member_relationship r on r.son_id=m.id where r.parent_id='{$_SESSION['sid']}' and r.son_id_type=3 and r.status=0 and r.ship_type=1 and m.status=0";
$GLOBALS['le']->query($sql);
$myDistors=array();
while($row=$GLOBALS['le']->fetch_assoc()){
    $myDistors[]=$row['id'];
}
//print_r($myDistors);
//exit;
$memObject = new \pft\Member\MemberAccount($le,$_SESSION['sid']);
if(count($myDistors)>0) {
    $DistorsNames = $memObject->getMemName($myDistors);
}
//print_r($DistorsNames);
//获取结束
$all=!count(array_diff(array_keys($_auth),$chid))?"checked":"";
$gid=1;
$outnum=1;
foreach($_auth as $v){
	$px[]=$v['group'];
}
array_multisort($px,$_auth);
?>
<script type="text/javascript">
document.title="权限管理";
function chAll(e){//(取消)全选
	var x=document.getElementsByTagName("input");
	for(var i=0;i<x.length;i++){
		var obj = x[i];
		if(obj.type=="checkbox"){
			if(e.checked)
				obj.checked=true;
			else
				obj.checked=false;
		}
	}  
}
</script>
<style>
.operqx{float:right;width:800px;}
.operqx h4{ font-size:12px; font-weight:600; color:#666; background:#EFF1F5; height:30px; line-height:30px; padding-left:12px; margin:0; text-align:left; *width:815px; _width:816px;}
.operqx h4 span{ float:right; font-weight:400; margin-right:70px;}
.optaba{ width:100%; margin-bottom:20px; border-collapse:collapse; line-height:27px;}
.optaba th{ width:100px; text-align:center; font-weight:400;background:#eaf6ff; font-size:14px; color:#333;}
.optaba td{ padding-left:10px; font-size:12px; color:#000; width:270px;}
.butqd{ border:0; background:#237FD9; margin:5px 0 0 230px; color:#FFF; height:28px; line-height:28px; padding:0 10px; font-size:14px; cursor:pointer;}
.opercon{ font-size:12px; border:1px solid #cccccc; padding-bottom:20px;}
.opercon label{ margin-left:25px; height:25px; line-height:25px; display:inline-block; font-weight:400;}
.opercon label input{vertical-align:-2px;}
.opercon dl{ margin:4px 8px; line-height:27px; border-bottom:0 solid #ccc;}
.opercon dt{ padding-left:8px; color:#666; font-weight:700; font-size:13px; border-bottom:1px solid #ccc;}
.opercon dd{ margin-top:8px; padding-left:40px;}
.opercon dd span{ margin:3px 0px 0 0px; width:133px; display:inline-block;}
.opercon dd span input{vertical-align:-2px;}
</style>
<div class="operqx">
	
	<table cellpadding="0" bordercolor="#CCCCCC" cellspacing="0" border="1" class="optaba">
    	<tr>
        	<th colspan="4"><h4>员工基本信息</h4></th>
        </tr>
		<tr>
			<th>姓名</th>
			<td><?=$dname?></td>
			<th>所在部门</th>
			<td><?=$bizz?></td>
		</tr>
		<tr>
			<th>手机号码</th>
			<td><?=$mobile?></td>
			<th></th>
			<td></td>
		</tr>
	</table>
	<iframe name="ifr" style="display:none;"></iframe>
	<form action="powguanli.php" target="ifr">
		<input type="hidden" name="id" value="<?=$id?>" />
		<div class="opercon">
			<h4><a style="float:right;margin-right:20px;text-decoration: underline;" href="operlist.html">返回</a>权限管理<label><input type="checkbox" <?=$all?> onclick="chAll(this)"/> 全选</label></h4>
               <dt>供应商选择</dt>               
               <dl><dd>
               <?if(count($DistorsNames)){
               foreach($DistorsNames as $fid => $dname){?>
                    <span><input type="checkbox"  name="land[]" value="<?=$fid?>" /> <?=$dname?></span>
                    <?}}?>
                </dd></dl>
			<?	foreach($_auth as $k=>$v){
					if(!in_array($_SESSION['sdtype'],explode(",",$v['limit']))){continue;}
					$checked=in_array($k,$chid)?"checked":"";
					if($gid!=$v['group']){
						$gid=$v['group'];
						$outnum=1;?>
				</dd>
			</dl>
				<?	}
					if($outnum){
						$outnum=0;
						$group=$_auth_group[$gid];
						?>
			<dl>
				<dt><?=$group?></dt>
				<dd>
				<?	}?>
					<span><input type="checkbox" <?=$checked?> name="pow[]" value="<?=$k?>" /> <?=$v['title']?></span>
			<?	}?>
				</dd>
			</dl>
			<input type="submit" class="butqd" value="确定" />
			<input type="button" onclick="history.go(-1)" class="butqd" value="返回" />
		</div>
        <?print_r($_auth_group);
            print_r($_auth);
        ?>
	</form>
</div>

<?include("common/footer.html");?>